﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserList.aspx.cs" Inherits="FastTravel.IntranetWeb.UserList" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Список пользователей</title>
</head>
<body>
	<form id="formUserList" runat="server">
	<ext:ResourceManager ID="resourceManager" runat="server" Theme="Gray" DirectMethodNamespace="FastTravel.IntranetWeb"/>
		<!-- data storage -->
		<ext:Store ID="storeUserRole" runat="server">
			  <Reader>
				<ext:JsonReader IDProperty="Value">
					<Fields>
						<ext:RecordField Name="Text" />
						<ext:RecordField Name="Value" />
					</Fields>
				</ext:JsonReader>
			</Reader>           
		</ext:Store>

	<ext:GridPanel ID="grdUsers" runat="server" Title="Пользователи" AutoHeight="true" StripeRows="true" AutoExpandColumn="Login">
			<Store>
				<ext:Store ID="StoreUser" runat="server" OnRefreshData="StoreRefresh" RemoteSort="true">
					<Proxy>
					   <ext:PageProxy />
					</Proxy>
					<Reader>
						<ext:JsonReader IDProperty="ID" TotalProperty="total">
							<Fields>
								<ext:RecordField Name="ID" Type="Int"/>
								<ext:RecordField Name="Login" Type="String" SortDir="ASC"/>
								<ext:RecordField Name="LastName" Type="String" />
								<ext:RecordField Name="FirstName" Type="String" />
								<ext:RecordField Name="MiddleName" Type="String" />
								<ext:RecordField Name="IsBlocked" Type="Boolean"/>
								<ext:RecordField Name="UserRole"/>
							</Fields>
						</ext:JsonReader>
					</Reader>
					<BaseParams>
						<ext:Parameter Name="start" Value="0" Mode="Raw" />
						<ext:Parameter Name="limit" Value="10" Mode="Raw" />
						<ext:Parameter Name="sort" Value="Login" />
						<ext:Parameter Name="dir" Value="ASC" />
					</BaseParams>
					<SortInfo Field="Login" Direction="ASC" />
				</ext:Store>
			</Store>
			<TopBar>
				<ext:Toolbar runat="server" ID="toolBar" Height="30" EnableTheming="true">
					<Items>
						<ext:Button runat="server" Text="Новый пользователь"  Icon="Add">
							<DirectEvents>
									<Click OnEvent="BtnAddUserClick" >
									</Click>
							</DirectEvents>
						</ext:Button>
					</Items>
				</ext:Toolbar>
			</TopBar>
			<ColumnModel ID="columnUsers" runat="server" EnableTheming="true">
				<Columns>
					<ext:Column ColumnID="ID" Header="№" Width="40" DataIndex="ID" Hidden="true"/>
					<ext:Column Header="Логин" Width="80" DataIndex="Login"/>
					<ext:Column Header="Фамилия" Width="150" DataIndex="LastName" />
					<ext:Column Header="Имя" Width="150" DataIndex="FirstName" />
					<ext:Column Header="Отчество" Width="150" DataIndex="MiddleName" />
					<ext:CheckColumn DataIndex="IsBlocked" Header="Заблокирован" Width="90" />
					<ext:Column Header="Роль" Width="150" DataIndex="UserRole" />
					<ext:CommandColumn Width="55" Header="" Align="Center" Sortable="false">                                            
					   <Commands>                                               
						  <ext:GridCommand CommandName="Edit" Icon="Pencil" ToolTip-Text="Изменить">                                                        
						  </ext:GridCommand>
						  <ext:GridCommand CommandName="Delete" Icon="Cross" ToolTip-Text="Удалить">
						  </ext:GridCommand>
					   </Commands>
					</ext:CommandColumn>
				</Columns>
			</ColumnModel>
			<DirectEvents>                                        
				<Command OnEvent="GridAction" Buffer="250">
					<EventMask ShowMask="true" />
						<ExtraParams>
							<ext:Parameter Name="command" Value="command" Mode="Raw"/>
							<ext:Parameter Name="id" Value="record.id" Mode="Raw"/>
						</ExtraParams>
						<Confirmation BeforeConfirm="if (command=='Edit') return false;" ConfirmRequest="true" Message="Вы хотите удалить пользователя?" Title="Удаление пользователя" />
				</Command>
			</DirectEvents>
			<BottomBar>
				<ext:PagingToolbar ID="toolbarBottomPaging" runat="server" BeforePageText="Страница" AfterPageText="из" PageSize="10" DisplayInfo="true" DisplayMsg="Пользователи {0} - {1} из {2}      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" EmptyMsg="Нет пользователей"  LabelAlign="Left">
					<Items>
						<ext:Label ID="lblPageSize" runat="server" Text="Размер страницы:" />
						<ext:ToolbarSpacer ID="toolbarSpacer" runat="server" Width="10"/>
						<ext:ComboBox ID="comboPageSize" runat="server" Width="50">
							<Items>
								<ext:ListItem Text="10" />
								<ext:ListItem Text="15" />
								<ext:ListItem Text="20" />
								<ext:ListItem Text="30" />
								<ext:ListItem Text="50" />
							</Items>
							<SelectedItem Value="10" />
							<Listeners>
								<Select Handler="#{toolbarBottomPaging}.pageSize = parseInt(this.getValue()); #{toolbarBottomPaging}.doLoad();" />
							</Listeners>
						</ext:ComboBox>
					</Items>
				</ext:PagingToolbar>
			</BottomBar>
			<SelectionModel>
						<ext:RowSelectionModel ID="RowSelectionModel" runat="server" SingleSelect="true">
						</ext:RowSelectionModel>
			</SelectionModel>
			<LoadMask ShowMask="true" Msg="Загрузка данных о пользователях..."/>
			<SaveMask ShowMask="true" Msg="Сохранение данных о пользователе..."/>
		</ext:GridPanel>
		
		<!-- New user indow -->

		<ext:Window ID="winUserNew" runat="server" Icon="UserAdd" Width="400" Modal="true" Hidden="true" Layout="Fit" AutoHeight="true" Title="Добавление пользователя" >
			<Items>
				<ext:FormPanel ID="pnlUserNew" runat="server" Padding="5"	Layout="Form" AutoWidth="true" AutoHeight="true">
					<Items>
						<ext:TextField ID="txtLoginNew" runat="server" FieldLabel="Логин" Width="250" AllowBlank="false" SelectOnFocus="True"/>
						<ext:TextField ID="txtLastNameNew" runat="server" FieldLabel="Фамилия" Width="250" SelectOnFocus="True" />
						<ext:TextField ID="txtFirstNameNew" runat="server" FieldLabel="Имя" Width="250" SelectOnFocus="True"/>
						<ext:TextField ID="txtMiddleNameNew" runat="server" FieldLabel="Отчество" Width="250" SelectOnFocus="True" />
						<ext:Checkbox ID="chkIsBlockedNew" runat="server" FieldLabel="Заблокирован"/>
						<ext:TextField DataIndex="Password" ID="txtPasswordNew" runat="server" FieldLabel="Пароль" InputType="Password" AllowBlank="false" SelectOnFocus="True"/>
						<ext:TextField DataIndex="Password" ID="txtPasswordNewRepeat" runat="server" FieldLabel="Повторите пароль" 
						InputType="Password" Vtype="password" MsgTarget="Side" AllowBlank="false" VtypeText="Пароль не совпадает" SelectOnFocus="True">
								<CustomConfig>
									<ext:ConfigItem Name="initialPassField" Value="#{txtPasswordNew}" Mode="Value" />
								</CustomConfig> 
						</ext:TextField>
						<ext:ComboBox ID="comboUserRoleAdd" runat="server" FieldLabel="Роль" SelectedIndex="0" StoreID="storeUserRole" DisplayField="Text" ValueField="Value" Mode="Local"/>
					</Items>
					<Buttons>
						<ext:Button ID="btnAddNew" runat="server" Text="Добавить" Icon="Accept" >
							<DirectEvents>
									<Click OnEvent="BtnConfirmNewUser" />
							</DirectEvents>
							<Listeners>
								<Click Handler=" 
									canSubmit = false; 
									#{pnlUserNew}.items.each( 
									function(item) { canSubmit = item.validate();  if(!canSubmit) breack;
									}); return canSubmit;  " />
							</Listeners>
						</ext:Button>
						<ext:Button ID="btnCancelNew" runat="server" Text="Отменить" Icon="Decline" >
							<Listeners>
								<Click Handler="#{winUserNew}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>

		<!-- Edit user window -->

		<ext:Window ID="winEditUser" runat="server" Icon="UserEdit" Width="400" Modal="true" Hidden="true" Layout="Fit" AutoHeight="true" Title="Редактирование пользователя" >
						<Items>
				<ext:FormPanel ID="pnlUserEdit" runat="server" Padding="5"	Layout="Form" AutoWidth="true" AutoHeight="true">
					<Items>
						<ext:TextField ID="txtLoginEdit" runat="server" FieldLabel="Логин" Width="250" AllowBlank="false" SelectOnFocus="True"/>
						<ext:TextField ID="txtLastNameEdit" runat="server" FieldLabel="Фамилия" Width="250" SelectOnFocus="True" />
						<ext:TextField ID="txtFirstNameEdit" runat="server" FieldLabel="Имя" Width="250" SelectOnFocus="True"/>
						<ext:TextField ID="txtMiddleNameEdit" runat="server" FieldLabel="Отчество" Width="250" SelectOnFocus="True" />
						<ext:Checkbox ID="chkIsBlockedEdit" runat="server" FieldLabel="Заблокирован"/>
						<ext:Checkbox ID="chkEnableNewPassword" runat="server" FieldLabel="Изменить пароль" LabelAlign="Right">
		                    <Listeners>
								 <Check Handler="#{txtPasswordEdit}.setDisabled(!this.checked);#{txtPasswordEditRepeat}.setDisabled(!this.checked);" />
							</Listeners>
						</ext:Checkbox>
						<ext:TextField DataIndex="Password" ID="txtPasswordEdit" runat="server" FieldLabel="Новый пароль" InputType="Password" AllowBlank="false" SelectOnFocus="True" Disabled="true"/>
						<ext:TextField DataIndex="Password" ID="txtPasswordEditRepeat" runat="server" FieldLabel="Повторите пароль"
						InputType="Password" Vtype="password" MsgTarget="Side" AllowBlank="false" VtypeText="Пароль не совпадает" SelectOnFocus="True" Disabled="true">
								<CustomConfig>
									<ext:ConfigItem Name="initialPassField" Value="#{txtPasswordEdit}" Mode="Value" />
								</CustomConfig> 
						</ext:TextField>
						<ext:ComboBox ID="comboUserRoleEdit" runat="server" FieldLabel="Роль" SelectedIndex="0" StoreID="storeUserRole" DisplayField="Text" ValueField="Value" Mode="Local"/>
					</Items>
					<Buttons>
						<ext:Button ID="btnEditUser" runat="server" Text="Сохранить" Icon="Accept" >
							<DirectEvents>
									<Click OnEvent="BtnConfirmEditUser" />
							</DirectEvents>
							<Listeners>
								<Click Handler=" 
									canSubmit = false; 
									#{pnlUserEdit}.items.each( 
									function(item) { canSubmit = item.validate();  if(!canSubmit) breack;
									}); return canSubmit;  " />
							</Listeners>
						</ext:Button>
						<ext:Button ID="btnCancelEditUser" runat="server" Text="Отменить" Icon="Decline" >
							<Listeners>
								<Click Handler="#{winEditUser}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>
	</form>
</body>
</html>
